package com.clubupc.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class BeanTool {

	private static String defaultSQLTimeFormat = "hh:mm:ss";
	private static String defaultSQLDateFormat = "yyyy-MM-dd";
	private static String defaultSQLTimestampFormat = "yyyy-MM-dd hh:mm:ss";
	private static String defaultUtilDateFormat = "dd/mm/yyyy";

	public static Date getStringAsUtilDate(String strTime) {
		return getStringAsUtilDate(strTime, defaultUtilDateFormat);
	}

	public static Date getStringAsUtilDate(String strDate, String format) {
		Date newDate = null;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format, new Locale("es", "ES"));
			newDate = sdf.parse(strDate);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return newDate;
	}

	public static String getUtilDateAsString(Date date) {
		return getUtilDateAsString(date, defaultUtilDateFormat);
	}

	public static String getUtilDateAsString(Date date, String format) {
		String strNewDate = null;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format, new Locale("es", "ES"));
			if (date != null)
				strNewDate = sdf.format(date);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return strNewDate;
	}

	public static java.sql.Time getStringAsSQLTime(String strTime, String format) {
		return new java.sql.Time(getStringAsUtilDate(strTime, format).getTime());
	}

	public static java.sql.Time getStringAsSQLTime(String strTime) {
		return getStringAsSQLTime(strTime, defaultSQLTimeFormat);
	}

	public static String getSQLTimeAsString(java.sql.Time time, String format) {
		return getUtilDateAsString(time, format);
	}

	public static String getSQLTimeAsString(java.sql.Time time) {
		return getSQLTimeAsString(time, defaultSQLTimeFormat);
	}

	public static java.sql.Timestamp getStringAsSQLTimestamp(String strTimestamp, String format) {
		return new java.sql.Timestamp(getStringAsUtilDate(strTimestamp, format).getTime());
	}

	public static java.sql.Timestamp getStringAsSQLTimestamp(String strTimestamp) {
		return getStringAsSQLTimestamp(strTimestamp, defaultSQLTimestampFormat);
	}

	public static String getSQLTimestampAsString(java.sql.Timestamp timestamp, String format) {
		return getUtilDateAsString(timestamp, format);
	}

	public static String getSQLTimestampAsString(java.sql.Timestamp timestamp) {
		return getSQLTimestampAsString(timestamp, defaultSQLTimestampFormat);
	}

	public static String getSQLDateAsString(java.sql.Date date, String format) {
		return getUtilDateAsString(date, format);
	}

	public static String getSQLDateAsString(java.sql.Date time) {
		return getSQLDateAsString(time, defaultSQLDateFormat);
	}

	public static java.sql.Date getStringAsSQLDate(String date, String format) {
		return new java.sql.Date(getStringAsUtilDate(date, format).getTime());
	}

	public static java.sql.Date getStringAsSQLDate(String date) {
		return getStringAsSQLDate(date, defaultSQLDateFormat);
	}

	public static java.sql.Time getUtilDateAsSQLTime(Date date) {
		return getStringAsSQLTime(getUtilDateAsString(date, defaultSQLTimeFormat), defaultSQLTimeFormat);
	}

	public static Date getSQLTimeAsUtilDate(java.sql.Time time) {
		return getStringAsUtilDate(getSQLTimeAsString(time, defaultSQLTimeFormat), defaultSQLTimeFormat);
	}

	public static java.sql.Date getSQLTimeAsSQLDate(java.sql.Time time) {
		return getStringAsSQLDate(getSQLTimeAsString(time, defaultSQLTimeFormat), defaultSQLTimeFormat);
	}

	public static java.sql.Time getSQLDateAsSQLTime(java.sql.Date date) {
		return getStringAsSQLTime(getSQLDateAsString(date, defaultSQLTimeFormat), defaultSQLTimeFormat);
	}

	public static java.sql.Time getSQLTimestampAsSQLTime(java.sql.Timestamp timestamp) {
		return getStringAsSQLTime(getSQLTimestampAsString(timestamp, defaultSQLTimeFormat), defaultSQLTimeFormat);
	}

	public static java.sql.Timestamp getSQLTimeAsSQLTimestamp(java.sql.Time time) {
		return getStringAsSQLTimestamp(getSQLTimeAsString(time, defaultSQLTimeFormat), defaultSQLTimeFormat);
	}

	public static java.sql.Timestamp getUtilDateAsSQLTimestamp(Date date) {
		return getStringAsSQLTimestamp(getUtilDateAsString(date, defaultSQLTimestampFormat), defaultSQLTimestampFormat);
	}

	public static Date getSQLTimestampAsUtilDate(java.sql.Timestamp timestamp) {
		return getStringAsSQLDate(getUtilDateAsString(timestamp, defaultSQLTimestampFormat), defaultSQLTimestampFormat);
	}

	public static java.util.Date getSQLTimestampAsSQLDate(java.sql.Timestamp timestamp) {
		return getStringAsSQLDate(getUtilDateAsString(timestamp, defaultSQLDateFormat), defaultSQLDateFormat);
	}

	public static java.sql.Timestamp getSQLDateAsSQLTimestamp(java.sql.Date date) {
		return getStringAsSQLTimestamp(getSQLDateAsString(date, defaultSQLTimestampFormat), defaultSQLTimestampFormat);
	}

	public static java.sql.Date getUtilDateAsSQLDate(Date date) {
		return getStringAsSQLDate(getUtilDateAsString(date, defaultSQLDateFormat), defaultSQLDateFormat);
	}

	public static Date getSQLDateAsUtilDate(java.sql.Date date) {
		return getStringAsUtilDate(getSQLDateAsString(date, defaultUtilDateFormat), defaultUtilDateFormat);
	}
}
